import { ILoadMapTypeAll } from '@/common';
import { getLevelZeroJson, getLoadMapList, getSelectDataCommon, getTenantID } from '@/utils';
import { CGFSBG_STATE, DBZ_STATE, WJBZZ_STATE } from '../common/Format';

/**
 * @getSourceManageSearchColumns
 * @description 寻源管理数据表格信息展示和操作
 */
export const getSourceManageSearchColumns = (searchOperation) => {
  // 去除的实施状态
  const removeState = [DBZ_STATE(), WJBZZ_STATE(), CGFSBG_STATE()];

  // 字典id集合
  const loadMdicIds: string[] = [
    `${getTenantID()}${ILoadMapTypeAll.PURCHASE_METHOD}`,
    `${getTenantID()}${ILoadMapTypeAll.CURRYOUT_STATE}`,
    `${getTenantID()}${ILoadMapTypeAll.PURCHASE_CATEGORY}`,
  ];

  // 请求字典
  const { loadMapInfo } = getLoadMapList(loadMdicIds);

  // 实施状态
  const state = getSelectDataCommon(loadMapInfo?.[`${getTenantID()}${ILoadMapTypeAll.CURRYOUT_STATE}`], 'name', 'id')?.filter(
    (item) => removeState?.indexOf(item?.value) == -1,
  );

  // 采购类别
  // const supplyType = loadMapInfo?.[`${getTenantID()}${ILoadMapTypeAll.PURCHASE_CATEGORY}`];
  const supplyType = [
    {
      value: '0',
      name: '月度计划',
    },
    {
      value: '1',
      name: '零星采购',
    },
    // {
    //   value: '2',
    //   name: '实验平台',
    // },
  ];
  return [
    {
      name: 'packName',
      placeholder: '标包名称',
      label: '标包名称',
      componentType: 'Input',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'supplyWay',
      placeholder: '标的来源',
      label: '标的来源',
      componentType: 'Select',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
      dataSource: supplyType,
    },
    {
      name: 'procureReal',
      placeholder: '拟采用采购方式',
      label: '拟采用采购方式',
      componentType: 'TreeSelect',
      allowClear: true,
      md: 4,
      sm: 24,
      treeID: 'id',
      treeName: 'name',
      whetherSenior: false,
      dataSource: loadMapInfo?.[`${getTenantID()}${ILoadMapTypeAll.PURCHASE_METHOD}`],
    },
    {
      name: 'state',
      placeholder: '状态',
      label: '状态',
      componentType: 'Select',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
      dataSource: state,
    },
    {
      name: 'applyName',
      placeholder: '采购项目名称',
      label: '采购项目名称',
      componentType: 'SearchBigModal',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
      onClick: () => {
        searchOperation?.onOpen(true);
      },
    },
    // ==================高级搜索=================
    {
      name: 'expectSum',
      placeholder: '预算金额',
      label: '预算金额',
      componentType: 'NumberRange',
      allowClear: true,
      md: 6,
      sm: 24,
      whetherSenior: true,
    },
    {
      name: 'createTime',
      placeholder: '',
      label: '承办时间',
      componentType: 'RangePicker',
      allowClear: true,
      md: 6,
      sm: 24,
      whetherSenior: true,
    },
    {
      name: 'createFormName',
      placeholder: '承办',
      label: '承办',
      componentType: 'DeptAndUser',
      dataSource: getLevelZeroJson() ?? [],
      allowClear: true,
      md: 6,
      sm: 24,
      whetherSenior: true,
      formOrgType: {
        COMP: 'createCompanyID',
        DEPT: 'createDepartmentID',
        POS: 'createPositionID',
        USER: 'createrID',
      },
    },
  ];
};
